<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
$(function(){
	var product_categories_data = <?=$product_categories?>;
	$(document).mselect(product_categories_data, 'product_categories_id','product_categories_id', "<?=isset($_GET['product_categories_id'])?$_GET['product_categories_id']:0?>");
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$("#multiselect").multiselect({height: 260, minWidth: 160});
});
</script>

<fieldset><legend>查询条件</legend>
<form method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>发货日期</th>
	<td>
		<input type="text" class="datepicker" name="begin_shipped_time" value="<?=isset($_GET['begin_shipped_time']) ? $_GET['begin_shipped_time'] : ''?>" /> to 
		<input type="text" class="datepicker" name="end_shipped_time" value="<?=isset($_GET['end_shipped_time']) ? $_GET['end_shipped_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th>产品分类</th>
	<td><input type="hidden" id="product_categories_id" name="product_categories_id" /></td>
</tr>
<tr>
	<th>网站/店铺</th>
	<td>
		<select name="shop_id[]" multiple="multiple" id="multiselect">
		<?foreach ($shop_group as $k => $sg):?>
		<optgroup label="<?=$k?>">
		<?foreach ($sg as $s):?>
		<option value="<?=$s['id']?>" <?if (isset($_GET['shop_id']) && is_array($_GET['shop_id']) && in_array($s['id'], $_GET['shop_id'])) echo "selected='selected'"?>><?=$s['name']?></option>
		<?endforeach;?>
		</optgroup>
		<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<td><input type="hidden" name="is_search" value="1" /></td>
	<td><input type="submit" value="查询" class="button" /></td>
</tr>
</table>
</form></fieldset>

<?if (isset($result)):?>
<table class="list_table">
<tr>
	<th rowspan="2" width="100">店铺</th>
	<th rowspan="2" width="100">订单数</th>
	<th rowspan="2" width="100">产品数</th>
	<th rowspan="2" width="100">销售额</th>
	<th colspan="4">成本</th>
	<th rowspan="2" width="100">利润</th>
	<th rowspan="2" width="100">毛利率</th>
</tr>
<tr>
	<th width="100">产品成本</th>
	<th width="100">发货费用</th>
	<th width="100">PP费用5%</th>
	<th width="100">ebay费用10%</th>
</tr>
<?php foreach ($result as $r):?>
<tr>
	<td><?php echo $r['shopname']?></td>
	<td><?=$r['order_count']?></td>
	<td><?=$r['product_count']?></td>
	<td><?=sprintf('%.2f', $r['order_amount'])?></td>
	<td><?=sprintf('%.2f', $r['cost_amount'])?></td>
	<td><?=sprintf('%.2f', $r['postage_amount'])?></td>
	<td><?=sprintf('%.2f', $r['order_amount'] * 0.05)?></td>
	<td><?=sprintf('%.2f', $r['order_amount'] * 0.1)?></td>
	<td><?=sprintf('%.2f', $r['order_amount'] * 0.85 - $r['cost_amount'] - $r['postage_amount'])?></td>
	<td><?=$r['order_amount'] ? sprintf('%.2f', ($r['order_amount'] * 0.85 - $r['cost_amount'] - $r['postage_amount'])/$r['order_amount'] * 100) . '%' : '-'?></td>
</tr>
<?php endforeach;?>
</table>
<?endif;?>
<?php $this->_endblock();?>